package com.xinchao.ck_mips.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.widget.Toast;

/**
 * 更新APK后自己启动
 */

public class UpdatedAutoRunBroadCast extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equalsIgnoreCase("android.intent.action.PACKAGE_REPLACED")) {
            if (!TextUtils.isEmpty(intent.getDataString()) && intent.getDataString().equals("package:" + context.getPackageName())) {
                Toast.makeText(context, "升级成功", Toast.LENGTH_SHORT).show();
                Intent myApp = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
                context.startActivity(myApp);
            }
        }
    }
}
